﻿using Fierce.Utility.Helper;
using System;
using System.Linq;
using System.Text;
using Fierce.Core.Aop;
using Fierce.Entity.Basic;
using System.Collections.Generic;

namespace Fierce.Core.Service.Basic
{
    public partial class BasicSettingService : BaseService<BasicSetting>
    {
        public virtual BasicSetting GetByTag(string tag)
        {
            db.SaveChanges();

            return db.BasicSetting.Get(m => m.Tag == tag);
        }

        public virtual string GetContent(string tag)
        {
            var entity = GetByTag(tag);

            if (entity != null)
            {
                return entity.Content;
            }

            return string.Empty;
        }

        public virtual ServiceResult SetContent(List<BasicSetting> list)
        {
            foreach (var item in list)
            {
                var entity = GetByTag(item.Tag);

                if (entity != null)
                {
                    entity.Content = item.Content;
                    entity.Other = item.Other;

                    db.BasicSetting.Modified(entity);
                }
                else { db.BasicSetting.Added(item); }
            }
            return SaveAndResult("设置成功");
        }
    }
}